<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {
	public function index(){
		$this->layout->setTitle('User | Home');
		$smsCode = $this->session->userdata('user_sms_code');
		// get earning data
		$sqlThisMonthEarning = "SELECT sms_cost AS subtotal, 
								   DATE_FORMAT(receive_date, '%d-%m-%Y') AS earn_date
								FROM tdx_sms_stat WHERE sms_code='$smsCode'";
		$monthQuery = $this->db->query($sqlThisMonthEarning);
		if ($monthQuery->num_rows() > 0){
			$arrData = array();
			$total = 0;
			foreach ($monthQuery->result_array() as $row){
				$arrData[$row['earn_date']] += intval($row['subtotal']);
				$total += intval($row['subtotal']);
			}
		}
		$data['earn_this_month'] = $total;
		$data['month_data'] = $arrData;
		$this->layout->view(THEME_DIR.'/home_index', $data);
	}
}